package com.scy;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo08 {



    public static void main(String[] args) throws Exception {


       /* while (true){

            System.out.println("任务一");
            Thread.sleep(2000);

            System.out.println("任务二");
            Thread.sleep(3000);

            System.out.println("任务三");
            Thread.sleep(1000);
        }*/

        //线程池   存储很多个线程的池子
        ExecutorService service = Executors.newFixedThreadPool(10);

        /*
             图书列表服务
             图书上传服务
             图书下载服务
         */

        service.submit(()->{
            ServerSocket ss = new ServerSocket(10001);
            while (true) {
                System.out.println("开启图书列表服务...");
                Socket socket = ss.accept(); // 阻塞  等待客户端连接
                System.out.println("图书列表服务的客户端连接进来了...");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        service.submit(()->{
            ServerSocket ss = new ServerSocket(20000);
            while (true) {
                System.out.println("开启图书上传服务...");
                Socket socket = ss.accept();
                System.out.println("图书上传服务客户端连接进进来了");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        service.submit(()->{
            ServerSocket ss = new ServerSocket(30000);
            while (true) {
                System.out.println("开启图书下载服务...");
                Socket socket = ss.accept();
                System.out.println("图书下载服务的客户端连接进来了...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


    }


}
